from ums import umsservice as db
from flask import Blueprint, jsonify, redirect, url_for, request
import logging, requests
import sys, traceback, os, re
from utils.tokenutil import TokenUtil

logger = logging.getLogger('umsview')

ums = Blueprint("ums", __name__, url_prefix="/api/ums")

# 手机号验证码登录
@ums.route('/memberLoginForCode', methods=['GET'])
def umsmemberLoginForCode():
    param = {}
    param['phone'] = request.args.get('phone')
    param['code'] = request.args.get('code')
    return jsonify(db.umsmemberLoginForCode(param))

# 获取用户资料
@ums.route('/getMember', methods=['GET'])
def umsgetMember():
    # 从HTTP头部中获取token
    token = request.headers.get('token')
    param = {}
    param['memberId'] = TokenUtil.getMemberId(token)
    return jsonify(db.umsgetMember(param))

# 账号密码登录
@ums.route('/memberLogin', methods=['GET'])
def memberLogin():
    param = {}
    param['phone'] = request.args.get('phone')
    param['password'] = request.args.get('password')
    param['memberrole'] = request.args.get('memberrole')
    return jsonify(db.memberLogin(param))

# 获取用户资料
@ums.route('/getMemberBySn', methods=['GET'])
def getMemberBySn():
    param = {}
    param['memberSn'] = request.args.get('memberSn')
    return jsonify(db.getMemberBySn(param))
